<?php

namespace app\models\common;

use think\Model;

class ResponseLogModel extends Model
{
    protected $connection = 'mongodb';
    protected $table = 'cm_response_log';


    public function createRecord(array $params = [])
    {
        $data = [
            'http_code' => (string)($params['http_code'] ?? ''),
            'method' => $params['method'] ?? '',
            'route_prefix' => $params['route_prefix'] ?? '',
            'route_name' => $params['route_name'] ?? '',
            'request_path' => $params['request_path'] ?? '',
            'middleware' => $params['middleware'] ?? '',
            'header_data' => $params['header_data'] ?? '',
            'request_data' => $params['request_data'] ?? '',
            'response_data' => $params['response_data'] ?? '',
            'response_time' => $params['response_time'] ?? date('Y-m-d H:i:s'),
            'create_time' => date('Y-m-d H:i:s'),
        ];
        self::table($this->table)->insert($data);
        return true;
    }
}